layui.use(['table', 'layer'], function() {
	var $ = layui.$;
	var table = layui.table;
	var layer = layui.layer;
	var url = location.href;
	var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
	var id = paraString[0].substring(paraString[0].indexOf("=") + 1, paraString[0].length);
	var type = paraString[1].substring(paraString[1].indexOf("=") + 1, paraString[1].length);
	if(type == 'edit') {
		noreadonly();
		distributemsg();
	} else if(type == 'detail') {
		readonly();
		distributemsg();
	} else if(type == 'add') {

	}

	function distributemsg() {
		$.ajax({
			type: "post",
			url: "/distribute/msg",
			async: true,
			data: {
				id: id
			},
			success: function(data) {
				var result = JSON.parse(data.message);
				$(".orderman").val(result.orderman);
				$(".ordernumber").val(result.ordernumber);
				$(".ordercontxt").val(result.ordercontxt);
				$(".ordertime").val(result.ordertime);
				$(".orderdate").val(result.orderdate);
				if(result.distributeman == "") {
					$(".distributeman").val("未安排配送");
					$(".distributestarttime").val(result.distributestarttime);
					$(".distributeovertime").val(result.distributeovertime);
					$(".distributeman").css("color","red");
					$(".distributestarttime").css("color","red");
					$(".distributeovertime").css("color","red");
				} else {
					$(".distributeman").val(result.distributeman);
					$(".distributestarttime").val(result.distributestarttime);
					$(".distributeovertime").val(result.distributeovertime);
				}
			}
		});
	}

	function readonly() {
		$(".distributeman").attr("readonly","readonly");
		$(".distributestarttime").attr("readonly", "readonly");
		$(".distributeovertime").attr("readonly", "readonly");
	}

	function noreadonly() {
		$(".distributeman").removeAttr("readonly");
		$(".distributestarttime").removeAttr("readonly");
		$(".distributeovertime").removeAttr("readonly");
	}
});